<?php
/**
 * Created by PhpStorm.
 * Author: sitenv@aliyun.com
 * CreateTime: 2021/07/09 13:59
 * Blog：www.myblogs.xyz
 */

namespace app\common\model;


class Admin extends Common
{
    protected $name = 'admin';
    protected $pk = 'admin_id';

    public function adminLists($where = '', $limit = 1, $order = '', $field = '', $whereOr = '')
    {
        $data = $this->getLists($where, $limit, $order, $field, $whereOr);
        $list = $data['list'];
        if (is_array($list)){
            $role_model = new Role();
            foreach ($list as $key=>$val){
                $role_name = '没有权限';
                if (!empty($val['role_id'])){
                    $role_name = $role_model->getField($val['role_id'], 'role_name');
                }
                $list[$key]['role_name'] = $role_name;
            }
        }
        $data['list'] = $list;
        return $data;
    }

    public function agentLists($where = '', $limit = 1, $order = '', $field = '', $whereOr = '')
    {
        $data = $this->getLists($where, $limit, $order, $field, $whereOr);
        $list = $data['list'];
        if (!empty($list)){
            $vehicle_model = new Vehicle();
            if (is_array($list)){
                foreach ($list as $key=>$val){
                    $vehicle_number = $vehicle_model->where('admin_id', $val['admin_id'])->count();
                    $list[$key]['vehicle_number'] = $vehicle_number;
                }
            }
        }
        $data['list'] = $list;
        return $data;
    }

}